package com.rfid.a252robot.activity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.rfid.a252robot.R;
import com.rfid.a252robot.base.BaseAdapter;
import com.rfid.a252robot.bean.Box;
import com.rfid.db.bean.Book;
import com.rfid.util.Util;

import java.util.List;

public class BoxAdapter  extends BaseAdapter<BoxAdapter.ViewHolder, Box> {


    public BoxAdapter(List<Box> data) {
        super(data);
    }

    @Override
    protected void bindView(ViewHolder holder, int position) {
        Box box = mData.get(position);
        holder.textView.setText(Util.getBoxShow(box.getNum()));
        List<Book> books = box.getBooks();
        System.out.println("箱号:" + box.getNum() + "- book size " + books.size());
        if (books != null && books.size() > 0) {
            holder.bookStatus.setVisibility(View.VISIBLE);
        } else {
            holder.bookStatus.setVisibility(View.GONE);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BoxAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_box_layout,parent,false));
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        TextView bookStatus;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.title);
            bookStatus = itemView.findViewById(R.id.bookStatus);
        }
    }
}
